<template>
  <PageWrapper>
    <template #headerContent> <WorkbenchHeader @success="workbenchHeaderSuccess" /> </template>
    <div class="lg:flex">
      <div class="lg:w-9/12 w-full !mr-4 enter-y">
        <ProjectCard :loading="loading" class="enter-y" :statisticsData="statisticsData"/>
        <IndexChart class="!my-4 enter-y" :curCompanyId="curCompanyId" />
      </div>
      <div class="lg:w-3/12 w-full enter-y">
        <QuickNav :loading="loading" class="enter-y" />
        <SaleRadar :loading="loading" class="enter-y" />
      </div>
    </div>
  </PageWrapper>
</template>
<script lang="ts" setup>
  import { ref } from 'vue';
  import { Card } from 'ant-design-vue';
  import { PageWrapper } from '/@/components/Page';
  import WorkbenchHeader from './components/WorkbenchHeader.vue';
  import ProjectCard from './components/ProjectCard.vue';
  import QuickNav from './components/QuickNav.vue';
  import IndexChart from './components/IndexChart.vue';
  import SaleRadar from './components/SaleRadar.vue';
  import { queryIndexStatistics } from "/@/api/sys/index";

  const loading = ref(false);
  const curCompanyId = ref("");
  // setTimeout(() => {
  //   loading.value = false;
  // }, 500);

  const statisticsData = ref<any>({
    rechargeAmount: 0.00,
    withdrawalAmount: 0.00,
    serviceFee: 0.00,
    drawbackAmount: 0.00,
    drawbackServiceCharge: 0.00
  });

    /**
     * 查询条件选择成功返回
     * @param data
     */
    function workbenchHeaderSuccess(data){
      console.log("查询条件：",data)
      let startDate,endDate;
      if(data.rangeDateKey==='zdy'){
        startDate = data.rangeDate[0];
        endDate = data.rangeDate[1];
      }
      curCompanyId.value = data.companyId;
      queryStatisticsData(data.companyId,data.rangeDateKey,startDate,endDate);
    }

    /**
     * 统计查询
     * @param companyId
     * @param dateType
     * @param timeBegin
     * @param timeEnd
     */
    function queryStatisticsData(companyId,dateType,timeBegin,timeEnd){
      loading.value = true;
      queryIndexStatistics({
        companyId: companyId,
        dateType: dateType,
        timeBegin: timeBegin,
        timeEnd: timeEnd}).then((res) => {
        statisticsData.value = res.result;
      }).finally(() => {
        loading.value = false;
      });
      // console.log("查询数据：",statisticsData.value);
    }

</script>
